package com.minelx.woods.server.common;

import java.util.function.UnaryOperator;
import java.util.stream.IntStream;

public class IndexesStreamAt<E> implements IAt<E> {

	private final E[] values;

	private final IntStream indexes;

	public IndexesStreamAt(E[] values, IntStream indexes) {
		this.indexes = indexes;
		this.values = values;
	}

	@Override
	public void set(E value) {
		indexes.forEach(index -> values[index] = value);
	}

	@Override
	public void map(UnaryOperator<E> mapper) {
		indexes.forEach(index -> values[index] = mapper.apply(values[index]));
	}
}
